home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 March
/
Chip_2002-03_cd1.bin
/
zkuste
/
delphi
/
kolekce
/
d3456
/
gmprintsuite_eval.exe
/
{app}
/
GmLegacy.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-01-09
|
38KB
|
1,274 lines
unit GmLegacy;
interface
uses Windows, Classes, Graphics, Dialogs, GmTypes, GmObjects;
type
{$IFNDEF VER100}
PointArray = array of TPoint;
{$ENDIF}
TGmBaseFileRec = class
private
FID: Extended;
end;
TGmExtFileRec = class(TGmBaseFileRec)
private
FValue: Extended;
end;
TGmIntFileRec = class(TGmBaseFileRec)
private
FValue: Integer;
end;
TGmStrFileRec = class(TGmBaseFileRec)
private
FValue: string
end;
TGmBrushFileRec = class(TGmBaseFileRec)
private
FValue: TGmBrush;
end;
TGmFontFileRec = class(TGmBaseFileRec)
private
FValue: TGmFont;
end;
TGmPenFileRec = class(TGmBaseFileRec)
private
FValue: TGmPen;
end;
TGmExtValueList = class
private
//FObjectID : Extended;
FExtList: TList;
FIntList: TList;
FStrList: TList;
FBrushList: TList;
FFontList: TList;
FPenList: TList;
FMemoryBuffer: TMemoryStream;
function GetBoolValue(AIndex: Extended): Boolean;
function GetExtValue(AIndex: Extended): Extended;
function GetIntValue(AIndex: Extended): Integer;
function GetIntValueDef(AIndex: Extended; DefaultVal: integer): Integer;
function GetStrValue(AIndex: Extended): string;
function GetGmBrush(AIndex: Extended): TGmBrush;
function GetGmFont(AIndex: Extended): TGmFont;
function GetGmPen(AIndex: Extended): TGmPen;
function FontStringToStyle(AStyle: string): TFontStyles;
function FontStyleToString(AStyle: TFontStyles): string;
public
constructor Create;
destructor Destroy; override;
procedure LoadFromStream(AStream: TStream);
procedure SaveToStream(AStream: TStream);
procedure Clear;
procedure AddBoolVal(AID: Extended; AValue: Boolean);
procedure AddExtVal(AID: Extended; AValue: Extended);
procedure AddIntVal(AID: Extended; AValue: Integer);
procedure AddStrVal(AID: Extended; AValue: string);
procedure AddGmBrush(AID: Extended;AGmBrush: TGmBrush);
procedure AddGmFont(AID: Extended; AGmFont: TGmFont);
procedure AddGmPen(AID: Extended; AGmPen: TGmPen);
function IntFromStream(AStream: TStream): LongInt;
function FloatFromStream(AStream: TStream): Extended;
function StrFromStream(AStream: TStream): string;
function BrushFromStream(AStream: TStream): TGmBrush;
function FontFromStream(AStream: TStream): TGmFont;
function PenFromStream(AStream: TStream): TGmPen;
procedure IntToStream(AStream: TStream; AInteger: LongInt);
procedure FloatToStream(AStream: TStream; AExtended: Extended);
procedure StrToStream(AStream: TStream; AString: string);
procedure BrushToStream(AStream: TStream; ABrush: TGmBrush);
procedure FontToStream(AStream: TStream; AFont: TGmFont);
procedure PenToStream(AStream: TStream; APen: TGmPen);
property ValueBool[index: Extended]: Boolean read GetBoolValue;
property ValueExt[index: Extended]: Extended read GetExtValue;
//property ValueInt[index: Extended]: Integer read GetIntValue;
property ValueInt[index: Extended; DefaultVal: integer]: Integer read GetIntValueDef;
property ValueStr[index: Extended]: string read GetStrValue;
property ValueBrush[index: Extended]: TGmBrush read GetGmBrush;
property ValueFont[index: Extended]: TGmFont read GetGmFont;
property ValuePen[index: Extended]: TGmPen read GetGmPen;
end;
procedure LoadFromStreamOld(APreview: TComponent; AStream: TStream);
procedure LoadOldObject({APreview: TComponent;} NewObject: TGmBaseObject; AValues: TGmExtValueList);
function BitmapFromStream(Fs: TStream): TBitmap;
function BoolFromStream(Fs: TStream): Boolean;
procedure BitmapToStream(Fs: TStream; AGraphic: TBitmap);
procedure BoolToStream(Fs: TStream; ABoolean: Boolean);
procedure BrushFromStream(Fs: TStream; var ABrush: TGmBrush);
procedure BrushToStream(Fs: TStream; ABrush: TGmBrush);
function FloatFromStream(Fs: TStream): Extended;
procedure FloatToStream(Fs: TStream; AExtended: Extended);
procedure FontFromStream(Fs: TStream; var AFont: TGmFont);
procedure FontToStream(Fs: TStream; AFont: TGmFont);
function IntFromStream(Fs: TStream): LongInt;
procedure IntToStream(Fs: TStream; AInteger: LongInt);
function MetafileFromStream(Fs: TStream): TMetaFile;
procedure MetaFileToStream(Fs: TStream; AGraphic: TMetaFile);
procedure PenFromStream(Fs: TStream; var APen: TGmPen);
procedure PenToStream(Fs: TStream; APen: TGmPen);
function StrFromStream(Fs: TStream): string;
procedure StrToStream(Fs: TStream; AString: string);
function FontStringToStyle(AStyle: string): TFontStyles;
function FontStyleToString(AStyle: TFontStyles): string;
procedure StringToStream(AString: string; AStream: TStream);
function StreamToString(AStream: TStream): string;
function BitmapFromString(AString: string): TBitmap;
function BitmapToString(ABitmap: TBitmap): string;
function MetafileFromString(AString: string): TMetafile;
function MetafileToString(AMetafile: TMetafile): string;
{$IFNDEF VER100}
function PolyPointsToString(APoints: PointArray): string;
procedure PolyPointsFromString(var APoints: PointArray; AString: string);
{$ENDIF}
implementation
uses GmConst, SysUtils, GmPreview;
procedure LoadFromStreamOld(APreview: TComponent; AStream: TStream);
var
AValues: TGmExtValueList;
NewObject: TGmBaseObject;
// two page variables used to give OnLoadProgress information...
//TotalPages: integer;
Preview: TGmPreview;
FirstPage: Boolean;
begin
// introduced with v2.14...
FirstPage := True;
//FPreviewState := gmLoading;
Preview := TGmPreview(APreview);
Preview.MessagesEnabled := False;
Preview.Clear;
AValues := TGmExtValueList.Create;
with AValues do
try
while AStream.Position < AStream.Size do
begin
NewObject := nil; // initialise the page object.
// page setup...
AValues.LoadFromStream(AStream);
case ValueInt[C_OBJECT, -1] of
C_NEW_PAGE:
begin
if not FirstPage then Preview.NewPage;
FirstPage := False;
//Inc(CurrentTotal);
//if Assigned(FOnLoadProgress) then FOnLoadProgress(Self, Round((CurrentTotal/TotalPages)*100));
end;
C_PAGE_SETUP:
begin
Preview.PageWidth.AsUnits := AValues.ValueInt[C_PAGE_WIDTH, 0];
Preview.PageHeight.AsUnits := AValues.ValueInt[C_PAGE_HEIGHT, 0];
Preview.PaperSize := TGmPaperSize(AValues.ValueInt[C_PAPER_SIZE, 0]);
Preview.Orientation := TGmOrientation(AValues.ValueInt[C_ORIENTATION, 0]);
end;
C_MARGIN:
begin
Preview.Margins.Left.AsUnits := ValueInt[C_MARGIN_LEFT, 0];
Preview.Margins.Top.AsUnits := ValueInt[C_MARGIN_TOP, 0];
Preview.Margins.Right.AsUnits := ValueInt[C_MARGIN_RIGHT, 0];
Preview.Margins.Bottom.AsUnits := ValueInt[C_MARGIN_BOTTOM, 0];
Preview.Margins.Visible := Boolean(ValueInt[C_MARGIN_VISIBLE, 0]);
Preview.Margins.ShowPrinterMargins := Boolean(ValueInt[C_PRINT_MARGIN_VISIBLE, 0]);
GmPenToPen(Preview.Margins.Pen, ValuePen[C_MARGINS_PEN_1]);
GmPenToPen(Preview.Margins.PrinterMarginPen, ValuePen[C_MARGINS_PEN_2]);
end;
C_SHADOW:
begin
Preview.Shadow.Color := AValues.ValueInt[C_SHADOW_COLOR, 0];
Preview.Shadow.Width := AValues.ValueInt[C_SHADOW_WIDTH, 0];
Preview.Shadow.Visible := Boolean(AValues.ValueInt[C_SHADOW_VISIBLE, 0]);
end;
C_DOCUMENT:
begin
// nothing is currently done with these values... (for future use)
ValueExt[C_DOCUMENT_CREATED];
//TotalPages := ValueInt[C_DOCUMENT_NUMPAGES, 0];
end;
C_HEADER:
begin
Preview.Header.ShowLine := Boolean(AValues.ValueInt[C_HEADER_SHOWLINE, 0]);
Preview.Header.Visible := Boolean(AValues.ValueInt[C_HEADER_VISIBLE, 0]);
//Preview.Header.CaptionLeft.LoadFromString(AValues.ValueStr[C_CAPTION_LEFT]);
//Preview.Header.CaptionCenter.LoadFromString(AValues.ValueStr[C_CAPTION_CENTER]);
//Preview.Header.CaptionRight.LoadFromString(AValues.ValueStr[C_CAPTION_RIGHT]);
GmPenToPen(Preview.Header.Pen, AValues.ValuePen[C_PEN]);
end;
C_FOOTER:
begin
Preview.Footer.ShowLine := Boolean(AValues.ValueInt[C_FOOTER_SHOWLINE, 0]);
Preview.Footer.Visible := Boolean(AValues.ValueInt[C_FOOTER_VISIBLE, 0]);
///Preview.Footer.FCaptionLeft.LoadFromString(AValues.ValueStr[C_CAPTION_LEFT]);
//Preview.Footer.FCaptionCenter.LoadFromString(AValues.ValueStr[C_CAPTION_CENTER]);
//Preview.Footer.FCaptionRight.LoadFromString(AValues.ValueStr[C_CAPTION_RIGHT]);
GmPenToPen(Preview.Footer.Pen, AValues.ValuePen[C_PEN]);
end;
C_OBJECT:
begin
case ValueInt[C_OBJECT_ID, -1] of
1: NewObject := TGmTextObject.Create;
2: NewObject := TGmLineObject.Create;
3: NewObject := TGmEllipseShape.Create;
4: NewObject := TGmRectangleShape.Create;
5: NewObject := TGmRoundRectShape.Create;
6: NewObject := TGmTextBoxObject.Create;
{$IFNDEF VER100}
7: NewObject := TGmPolygonObject.Create;
8: NewObject := TGmPolyLineObject.Create;
13: NewObject := TGmPolyBezierObject.Create;
{$ENDIF}
9: NewObject := TGmGraphicObject.Create;
10: NewObject := TGmArcShape.Create;
11: NewObject := TGmChordShape.Create;
12: NewObject := TGmPieShape.Create;
end;
if Assigned(NewObject) then
begin
LoadOldObject(NewObject, AValues);
Preview.Canvas.Page.AddObject(NewObject);
end;
end;
end;
end;
finally
AValues.Free;
// update the display...
Preview.MessagesEnabled := True;
Preview.UpdatePreview;
end;
end;
procedure LoadOldObject({APreview: TComponent;} NewObject: TGmBaseObject; AValues: TGmExtValueList);
//var
//Preview: TGmPreview;
begin
//Preview := TGmPreview(APreview);
if (NewObject is TGmSimpleShape) then
begin
with (NewObject as TGmSimpleShape) do
begin
Page := AValues.ValueInt[C_OBJECT_PAGE, 1];
X := AValues.ValueInt[C_OBJECT_X1, 0];
Y := AValues.ValueInt[C_OBJECT_Y1, 0];
X2 := AValues.ValueInt[C_OBJECT_X2, 0];
Y2 := AValues.ValueInt[C_OBJECT_Y2, 0];
if (NewObject is TGmRoundRectShape) then
begin
TGmRoundRectShape(NewObject).X3 := AValues.ValueInt[C_OBJECT_X3, 0];
TGmRoundRectShape(NewObject).Y3 := AValues.ValueInt[C_OBJECT_Y3, 0];
end;
if (NewObject is TGmComplexShape) then
begin
TGmComplexShape(NewObject).X3 := AValues.ValueInt[C_OBJECT_X3, 0];
TGmComplexShape(NewObject).Y3 := AValues.ValueInt[C_OBJECT_Y3, 0];
TGmComplexShape(NewObject).X4 := AValues.ValueInt[C_OBJECT_X4, 0];
TGmComplexShape(NewObject).Y4 := AValues.ValueInt[C_OBJECT_Y4, 0];
end;
Brush := AValues.ValueBrush[C_BRUSH];
Pen := AValues.ValuePen[C_PEN];
end;
end
else
if (NewObject is TGmLineObject) then
begin
with (NewObject as TGmLineObject) do
begin
Page := AValues.ValueInt[C_OBJECT_PAGE, 1];
X := AValues.ValueInt[C_OBJECT_X1, 0];
Y := AValues.ValueInt[C_OBJECT_Y1, 0];
X2 := AValues.ValueInt[C_OBJECT_X2, 0];
Y2 := AValues.ValueInt[C_OBJECT_Y2, 0];
LineType := TGmLineType(AValues.ValueInt[C_OBJECT_LINE_TYPE, 0]);
if LineType = GmLineExt then showmessage('d');
Pen := AValues.ValuePen[C_PEN];
end;
end
else
if (NewObject is TGmTextObject) then
begin
with (NewObject as TGmTextObject) do
begin
Page := AValues.ValueInt[C_OBJECT_PAGE, 1];
X := AValues.ValueInt[C_OBJECT_X1, 0];
Y := AValues.ValueInt[C_OBJECT_Y1, 0];
Brush := AValues.ValueBrush[C_BRUSH]; //GetGmBrush;
Font := AValues.ValueFont[C_FONT]; //GetGmFont;
Caption := AValues.ValueStr[C_CAPTION];
if (NewObject is TGmTextBoxObject) then
begin
TGmTextBoxObject(NewObject).X2 := AValues.ValueInt[C_OBJECT_X2, 0];
TGmTextBoxObject(NewObject).Y2 := AValues.ValueInt[C_OBJECT_Y2, 0];
TGmTextBoxObject(NewObject).Alignment := TAlignment(AValues.ValueInt[C_ALIGNMENT, 0]);
TGmTextBoxObject(NewObject).VertAlignment:= AValues.ValueInt[C_VERT_ALIGNMENT, 0];
TGmTextBoxObject(NewObject).Pen := AValues.ValuePen[C_PEN];
end;
end;
end
else
if (NewObject is TGmGraphicObject) then
begin
with (NewObject as TGmGraphicObject) do
begin
Page := AValues.ValueInt[C_OBJECT_PAGE, 1];
X := AValues.ValueInt[C_OBJECT_X1, 0];
Y := AValues.ValueInt[C_OBJECT_Y1, 0];
X2 := AValues.ValueInt[C_OBJECT_X2, 0];
Y2 := AValues.ValueInt[C_OBJECT_Y2, 0];
AType := TGmGraphicType(AValues.ValueInt[C_OBJECT_DATA1, 0]);
DrawAsBitmap := AValues.ValueBool[C_METAFILE_AS_BITMAP];
if AType = gtBitmap then
Bitmap := BitmapFromString(AValues.ValueStr[C_BITMAP])
else
if AType = gtMetafile then
Metafile := MetafileFromString(AValues.ValueStr[C_METAFILE]);
end;
end;
end;
constructor TGmExtValueList.Create;
begin
inherited;
FExtList := TList.Create;
FIntList := TList.Create;
FStrList := TList.Create;
FBrushList := TList.Create;
FFontList := TList.Create;
FPenList := TList.Create;
FMemoryBuffer := TMemoryStream.Create;
end;
destructor TGmExtValueList.Destroy;
begin
FMemoryBuffer.Free;
FExtList.Free;
FIntList.Free;
FStrList.Free;
FBrushList.Free;
FFontList.Free;
FPenList.Free;
inherited;
end;
function TGmExtValueList.GetBoolValue(AIndex: Extended): Boolean;
begin
Result := Boolean(GetIntValue(AIndex));
end;
function TGmExtValueList.GetExtValue(AIndex: Extended): Extended;
var
ICount: integer;
SearchRec: TGmExtFileRec;
begin
Result := 0;
for ICount := 0 to FExtList.Count-1 do
begin
SearchRec := TGmExtFileRec(FExtList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break;
end;
end;
end;
function TGmExtValueList.GetIntValue(AIndex: Extended): Integer;
var
ICount: integer;
SearchRec: TGmIntFileRec;
begin
Result := 0;
for ICount := 0 to FIntList.Count-1 do
begin
SearchRec := TGmIntFileRec(FIntList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break;
end;
end;
end;
function TGmExtValueList.GetIntValueDef(AIndex: Extended; DefaultVal: integer): Integer;
var
ICount: integer;
SearchRec: TGmIntFileRec;
begin
Result := DefaultVal;
for ICount := 0 to FIntList.Count-1 do
begin
SearchRec := TGmIntFileRec(FIntList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break;
end;
end;
end;
function TGmExtValueList.GetStrValue(AIndex: Extended): string;
var
ICount: integer;
SearchRec: TGmStrFileRec;
begin
Result := '';
for ICount := 0 to FStrList.Count-1 do
begin
SearchRec := TGmStrFileRec(FStrList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break ;
end;
end;
end;
function TGmExtValueList.GetGmBrush(AIndex: Extended): TGmBrush;
var
ICount: integer;
SearchRec: TGmBrushFileRec;
begin
for ICount := 0 to FBrushList.Count-1 do
begin
SearchRec := TGmBrushFileRec(FBrushList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break ;
end;
end;
end;
function TGmExtValueList.GetGmFont(AIndex: Extended): TGmFont;
var
ICount: integer;
SearchRec: TGmFontFileRec;
begin
for ICount := 0 to FFontList.Count-1 do
begin
SearchRec := TGmFontFileRec(FFontList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break ;
end;
end;
end;
function TGmExtValueList.GetGmPen(AIndex: Extended): TGmPen;
var
ICount: integer;
SearchRec: TGmPenFileRec;
begin
for ICount := 0 to FPenList.Count-1 do
begin
SearchRec := TGmPenFileRec(FPenList[ICount]);
if SearchRec.FID = AIndex then
begin
Result := SearchRec.FValue;
Break;
end;
end;
end;
function TGmExtValueList.FontStringToStyle(AStyle: string): TFontStyles;
begin
Result := [];
if Pos('B', AStyle) <> 0 then Result := Result + [fsBold];
if Pos('I', AStyle) <> 0 then Result := Result + [fsItalic];
if Pos('U', AStyle) <> 0 then Result := Result + [fsUnderline];
if Pos('S', AStyle) <> 0 then Result := Result + [fsStrikeOut];
end;
function TGmExtValueList.FontStyleToString(AStyle: TFontStyles): string;
begin
Result := '';
if (fsBold in AStyle) then Result := Result + 'B';
if (fsItalic in AStyle) then Result := Result + 'I';
if (fsUnderline in AStyle) then Result := Result + 'U';
if (fsStrikeOut in AStyle) then Result := Result + 'S';
end;
procedure TGmExtValueList.LoadFromStream(AStream: TStream);
var
StreamSize: integer;
ObjectType: integer;
AExtRec : TGmExtFileRec;
AIntRec : TGmIntFileRec;
AStrRec : TGmStrFileRec;
ABrushRec : TGmBrushFileRec;
AFontRec : TGmFontFileRec;
APenRec : TGmPenFileRec;
begin
Clear;
FMemoryBuffer.Clear;
StreamSize := IntFromStream(AStream);
FMemoryBuffer.SetSize(StreamSize);
FMemoryBuffer.CopyFrom(AStream, StreamSize);
FMemoryBuffer.Seek(0, soFromBeginning);
while (FMemoryBuffer.Position < FMemoryBuffer.Size) do
begin
ObjectType := IntFromStream(FMemoryBuffer);
case ObjectType of
C_EXTENDED:
begin
// create and add the Extended record...
AExtRec := TGmExtFileRec.Create;
AExtRec.FID := FloatFromStream(FMemoryBuffer);
AExtRec.FValue:= FloatFromStream(FMemoryBuffer);
FExtList.Add(AExtRec);
end;
C_INTEGER :
begin
// create and add the integer record...
AIntRec := TGmIntFileRec.Create;
AIntRec.FID := FloatFromStream(FMemoryBuffer);
AIntRec.FValue:= IntFromStream(FMemoryBuffer);
FIntList.Add(AIntRec);
end;
C_STRING :
begin
// create and add the string record...
AStrRec := TGmStrFileRec.Create;
AStrRec.FID := FloatFromStream(FMemoryBuffer);
AStrRec.FValue:= StrFromStream(FMemoryBuffer);
FStrList.Add(AStrRec);
end;
C_BRUSH :
begin
// create and add the string record...
ABrushRec := TGmBrushFileRec.Create;
ABrushRec.FID := FloatFromStream(FMemoryBuffer);
ABrushRec.FValue:= BrushFromStream(FMemoryBuffer);
FBrushList.Add(ABrushRec);
end;
C_FONT :
begin
// create and add the string record...
AFontRec := TGmFontFileRec.Create;
AFontRec.FID := FloatFromStream(FMemoryBuffer);
AFontRec.FValue:= FontFromStream(FMemoryBuffer);
FFontList.Add(AFontRec);
end;
C_PEN :
begin
// create and add the string record...
APenRec := TGmPenFileRec.Create;
APenRec.FID := FloatFromStream(FMemoryBuffer);
APenRec.FValue:= PenFromStream(FMemoryBuffer);
FPenList.Add(APenRec);
end;
end;
end;
end;
procedure TGmExtValueList.SaveToStream(AStream: TStream);
var
ICount: integer;
AExtRec: TGmExtFileRec;
AIntRec: TGmIntFileRec;
AStrRec: TGmStrFileRec;
ABrushRec: TGmBrushFileRec;
AFontRec: TGmFontFileRec;
APenRec: TGmPenFileRec;
begin
with FMemoryBuffer do
try
// write the file object ID...
//FloatToStream(MemStream, FObjectID);
// write the values to the list...
for ICount := 0 to FExtList.Count-1 do
begin
AExtRec := TGmExtFileRec(FExtList[ICount]);
IntToStream(FMemoryBuffer, C_EXTENDED);
FloatToStream(FMemoryBuffer, AExtRec.FID);
FloattoStream(FMemoryBuffer, AExtRec.FValue);
end;
for ICount := 0 to FIntList.Count-1 do
begin
AIntRec := TGmIntFileRec(FIntList[ICount]);
IntToStream(FMemoryBuffer, C_INTEGER);
FloatToStream(FMemoryBuffer, AIntRec.FID);
IntToStream(FMemoryBuffer, AIntRec.FValue);
end;
for ICount := 0 to FStrList.Count-1 do
begin
AStrRec := TGmStrFileRec(FStrList[ICount]);
IntToStream(FMemoryBuffer, C_STRING);
FloatToStream(FMemoryBuffer, AStrRec.FID);
StrToStream(FMemoryBuffer, AStrRec.FValue);
end;
for ICount := 0 to FBrushList.Count-1 do
begin
ABrushRec := TGmBrushFileRec(FBrushList[ICount]);
IntToStream(FMemoryBuffer, C_BRUSH);
FloatToStream(FMemoryBuffer, ABrushRec.FID);
BrushToStream(FMemoryBuffer, ABrushRec.FValue);
end;
for ICount := 0 to FFontList.Count-1 do
begin
AFontRec := TGmFontFileRec(FFontList[ICount]);
IntToStream(FMemoryBuffer, C_FONT);
FloatToStream(FMemoryBuffer, AFontRec.FID);
FontToStream(FMemoryBuffer, AFontRec.FValue);
end;
for ICount := 0 to FPenList.Count-1 do
begin
APenRec := TGmPenFileRec(FPenList[ICount]);
IntToStream(FMemoryBuffer, C_PEN);
FloatToStream(FMemoryBuffer, APenRec.FID);
PenToStream(FMemoryBuffer, APenRec.FValue);
end;
finally
IntToStream(AStream, FMemoryBuffer.Size);
FMemoryBuffer.SaveToStream(AStream);
FMemoryBuffer.Clear;
end;
Clear;
end;
procedure TGmExtValueList.Clear;
var
ICount: integer;
begin
// clear the ExtList...
for ICount := 0 to FExtList.Count-1 do
TGmExtFileRec(FExtList[ICount]).Free;
FExtList.Clear;
// clear the IntList...
for ICount := 0 to FIntList.Count-1 do
TGmIntFileRec(FIntList[ICount]).Free;
FIntList.Clear;
// clear the StrList...
for ICount := 0 to FStrList.Count-1 do
TGmStrFileRec(FStrList[ICount]).Free;
FStrList.Clear;
// clear the BrushList...
for ICount := 0 to FBrushList.Count-1 do
TGmBrushFileRec(FBrushList[ICount]).Free;
FBrushList.Clear;
// clear the FontList...
for ICount := 0 to FFontList.Count-1 do
TGmFontFileRec(FFontList[ICount]).Free;
FFontList.Clear;
// clear the PenList...
for ICount := 0 to FPenList.Count-1 do
TGmPenFileRec(FPenList[ICount]).Free;
FPenList.Clear;
end;
procedure TGmExtValueList.AddBoolVal(AID: Extended; AValue: Boolean);
begin
AddIntVal(AID, Ord(AValue));
end;
procedure TGmExtValueList.AddExtVal(AID: Extended; AValue: Extended);
var
NewObj: TGmExtFileRec;
begin
NewObj := TGmExtFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AValue;
FExtList.Add(NewObj);
end;
procedure TGmExtValueList.AddIntVal(AID: Extended; AValue: Integer);
var
NewObj: TGmIntFileRec;
begin
NewObj := TGmIntFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AValue;
FIntList.Add(NewObj);
end;
procedure TGmExtValueList.AddStrVal(AID: Extended; AValue: string);
var
NewObj: TGmStrFileRec;
begin
NewObj := TGmStrFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AValue;
FStrList.Add(NewObj);
end;
procedure TGmExtValueList.AddGmBrush(AID: Extended; AGmBrush: TGmBrush);
var
NewObj: TGmBrushFileRec;
begin
NewObj := TGmBrushFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AGmBrush;
FBrushList.Add(NewObj);
end;
procedure TGmExtValueList.AddGmFont(AID: Extended; AGmFont: TGmFont);
var
NewObj: TGmFontFileRec;
begin
NewObj := TGmFontFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AGmFont;
FFontList.Add(NewObj);
end;
procedure TGmExtValueList.AddGmPen(AID: Extended; AGmPen: TGmPen);
var
NewObj: TGmPenFileRec;
begin
NewObj := TGmPenFileRec.Create;
NewObj.FID := AID;
NewObj.FValue := AGmPen;
FPenList.Add(NewObj);
end;
function TGmExtValueList.IntFromStream(AStream: TStream): LongInt;
begin
AStream.ReadBuffer(Result, SizeOf(Result));
end;
function TGmExtValueList.FloatFromStream(AStream: TStream): Extended;
begin
AStream.ReadBuffer(Result, SizeOf(Result));
end;
function TGmExtValueList.StrFromStream(AStream: TStream): string;
var
StrLength: integer;
AString: string;
begin
AStream.ReadBuffer(StrLength, SizeOf(StrLength));
SetLength(AString, StrLength);
if StrLength > 0 then
AStream.ReadBuffer(AString[1], StrLength);
Result := AString;
end;
function TGmExtValueList.BrushFromStream(AStream: TStream): TGmBrush;
var
BrushValues: TGmExtValueList;
begin
BrushValues := TGmExtValueList.Create;
try
BrushValues.LoadFromStream(AStream);
Result.Color := BrushValues.ValueInt[C_BRUSH_COLOR, 0];
Result.Style := TBrushStyle(BrushValues.ValueInt[C_BRUSH_STYLE, Ord(bsSolid)]);
finally
BrushValues.Free;
end;
end;
function TGmExtValueList.FontFromStream(AStream: TStream): TGmFont;
var
FontValues: TGmExtValueList;
begin
FontValues := TGmExtValueList.Create;
try
FontValues.LoadFromStream(AStream);
Result.Name := FontValues.ValueStr[C_FONT_NAME];
Result.Angle := FontValues.ValueExt[C_FONT_ANGLE];
Result.Size := FontValues.ValueInt[C_FONT_SIZE, 12];
Result.Color := FontValues.ValueInt[C_FONT_COLOR, clBlack];
Result.Style := FontStringToStyle(FontValues.ValueStr[C_FONT_STYLE]);
finally
FontValues.Free;
end;
end;
function TGmExtValueList.PenFromStream(AStream: TStream): TGmPen;
var
PenValues: TGmExtValueList;
begin
PenValues := TGmExtValueList.Create;
try
PenValues.LoadFromStream(AStream);
Result.Color := PenValues.ValueInt[C_PEN_COLOR, clBlack];
Result.Width := PenValues.ValueInt[C_PEN_WIDTH, 1];
Result.Style := TPenStyle(PenValues.ValueInt[C_PEN_STYLE, Ord(psSolid)]);
Result.Mode := TPenMode(PenValues.ValueInt[C_PEN_MODE, Ord(pmCopy)]);
finally
PenValues.Free;
end;
end;
procedure TGmExtValueList.IntToStream(AStream: TStream; AInteger: LongInt);
var
WriteInt: LongInt;
begin
WriteInt := AInteger;
AStream.WriteBuffer(WriteInt, SizeOf(WriteInt));
end;
procedure TGmExtValueList.FloatToStream(AStream: TStream; AExtended: Extended);
var
WriteFloat: Extended;
begin
WriteFloat := AExtended;
AStream.WriteBuffer(WriteFloat, SizeOf(WriteFloat));
end;
procedure TGmExtValueList.StrToStream(AStream: TStream; AString: string);
var
StrLength: integer;
begin
StrLength := Length(AString);
AStream.Write(StrLength, SizeOf(StrLength));
if StrLength > 0 then
AStream.Write(AString[1], StrLength);
end;
procedure TGmExtValueList.BrushToStream(AStream: TStream; ABrush: TGmBrush);
var
BrushValues: TGmExtValueList;
begin
BrushValues := TGmExtValueList.Create;
try
BrushValues.AddIntVal(C_BRUSH_COLOR, ABrush.Color);
BrushValues.AddIntVal(C_BRUSH_STYLE, Ord(ABrush.Style));
BrushValues.SaveToStream(AStream);
finally
BrushValues.Free;
end;
end;
procedure TGmExtValueList.FontToStream(AStream: TStream; AFont: TGmFont);
var
FontValues: TGmExtValueList;
begin
FontValues := TGmExtValueList.Create;
try
FontValues.AddStrVal(C_FONT_NAME, AFont.Name);
FontValues.AddExtVal(C_FONT_ANGLE, AFont.Angle);
FontValues.AddIntVal(C_FONT_SIZE, AFont.Size);
FontValues.AddIntVal(C_FONT_COLOR, AFont.Color);
FontValues.AddStrVal(C_FONT_STYLE, FontStyleToString(AFont.Style));
FontValues.SaveToStream(AStream);
finally
FontValues.Free;
end;
end;
procedure TGmExtValueList.PenToStream(AStream: TStream; APen: TGmPen);
var
PenValues: TGmExtValueList;
begin
PenValues := TGmExtValueList.Create;
try
PenValues.AddIntVal(C_PEN_COLOR, APen.Color);
PenValues.AddIntVal(C_PEN_WIDTH, APen.Width);
PenValues.AddIntVal(C_PEN_STYLE, Ord(APen.Style));
PenValues.AddIntVal(C_PEN_MODE , Ord(APen.Mode));
PenValues.SaveToStream(AStream);
finally
PenValues.Free;
end;
end;
//------------------------------------------------------------------------------
function BitmapFromStream(Fs: TStream): TBitmap;
begin
Result := TBitmap.Create;
Result.LoadFromStream(Fs);
end;
procedure BitmapToStream(Fs: TStream; AGraphic: TBitmap);
begin
AGraphic.SaveToStream(Fs);
end;
//------------------------------------------------------------------------------
function BoolFromStream(Fs: TStream): Boolean;
begin
Fs.ReadBuffer(Result, SizeOf(Result));
end;
procedure BoolToStream(Fs: TStream; ABoolean: Boolean);
begin
Fs.WriteBuffer(ABoolean, SizeOf(ABoolean));
end;
//------------------------------------------------------------------------------
procedure BrushFromStream(Fs: TStream; var ABrush: TGmBrush);
var
AColor: TColor;
AStyle: TBrushStyle;
begin
AColor := ABrush.Color;
AStyle := ABrush.Style;
with Fs do
begin
ReadBuffer(AColor, SizeOf(AColor));
ReadBuffer(AStyle, SizeOf(AStyle));
end;
ABrush.Color := AColor;
ABrush.Style := AStyle;
end;
procedure BrushToStream(Fs: TStream; ABrush: TGmBrush);
var
AColor: TColor;
AStyle: TBrushStyle;
begin
AColor := ABrush.Color;
AStyle := ABrush.Style;
with Fs do
begin
WriteBuffer(AColor, SizeOf(AColor));
WriteBuffer(AStyle, SizeOf(AStyle));
end;
end;
//------------------------------------------------------------------------------
function FloatFromStream(Fs: TStream): Extended;
begin
Fs.ReadBuffer(Result, SizeOf(Result));
end;
procedure FloatToStream(Fs: TStream; AExtended: Extended);
var
WriteFloat: Extended;
begin
WriteFloat := AExtended;
Fs.WriteBuffer(WriteFloat, SizeOf(WriteFloat));
end;
//------------------------------------------------------------------------------
procedure FontFromStream(Fs: TStream; var AFont: TGmFont);
var
AStyle: TFontStyles;
begin
AFont.Name := StrFromStream(Fs);
AFont.Size := IntFromStream(Fs);
AFont.Color := IntFromStream(Fs);
AFont.Angle := 0;
Fs.Read(AStyle, SizeOf(AStyle));
AFont.Style := AStyle;
end;
procedure FontToStream(Fs: TStream; AFont: TGmFont);
var
AStyle: TFontStyles;
begin
AStyle := AFont.Style;
StrToStream(Fs, AFont.Name);
IntToStream(Fs, AFont.Size);
Fs.Write(AFont.Color, SizeOf(AFont.Color));
Fs.Write(AStyle, SizeOf(AStyle));
end;
//------------------------------------------------------------------------------
function IntFromStream(Fs: TStream): LongInt;
begin
Fs.ReadBuffer(Result, SizeOf(Result));
end;
procedure IntToStream(Fs: TStream; AInteger: LongInt);
var
WriteInt: LongInt;
begin
WriteInt := AInteger;
Fs.WriteBuffer(WriteInt, SizeOf(WriteInt));
end;
//------------------------------------------------------------------------------
function MetafileFromStream(Fs: TStream): TMetaFile;
var
MS: TMemoryStream;
MetafileSize: integer;
begin
// I have had to implement these two metafile functions because of
// bugs found in the TMetaFile.SaveToStream/LoadFromStream methods...
Result := TMetafile.Create;
MetafileSize := IntFromStream(Fs);
MS := TMemoryStream.Create;
MS.CopyFrom(Fs, MetaFileSize);
MS.Seek(0, soFromBeginning);
Result.LoadFromStream(MS);
MS.Clear;
MS.Free;
end;
procedure MetaFileToStream(Fs: TStream; AGraphic: TMetaFile);
var
MS: TMemoryStream;
begin
MS := TMemoryStream.Create;
AGraphic.SaveToStream(MS);
IntToStream(Fs, MS.Size);
MS.SaveToStream(Fs);
MS.Clear;
MS.Free;
end;
//------------------------------------------------------------------------------
procedure PenFromStream(Fs: TStream; var APen: TGmPen);
var
AColor: TColor;
AStyle: TPenStyle;
AWidth: Integer;
begin
with Fs do
begin
Fs.ReadBuffer(AColor, SizeOf(AColor));
Fs.ReadBuffer(AStyle, SizeOf(AStyle));
Fs.ReadBuffer(AWidth, SizeOf(AWidth));
end;
APen.Color := AColor;
APen.Style := AStyle;
APen.Width := AWidth;
end;
procedure PenToStream(Fs: TStream; APen: TGmPen);
var
AColor: TColor;
AStyle: TPenStyle;
AWidth: Integer;
begin
AColor := APen.Color;
AStyle := APen.Style;
AWidth := APen.Width;
with Fs do
begin
Fs.WriteBuffer(AColor, SizeOf(AColor));
Fs.WriteBuffer(AStyle, SizeOf(AStyle));
Fs.WriteBuffer(AWidth, SizeOf(AWidth));
end;
end;
//------------------------------------------------------------------------------
function StrFromStream(Fs: TStream): string;
var
StrLength: integer;
AString: string;
begin
Fs.ReadBuffer(StrLength, SizeOf(StrLength));
SetLength(AString, StrLength);
if StrLength > 0 then
Fs.ReadBuffer(AString[1], StrLength);
Result := AString;
end;
procedure StrToStream(Fs: TStream; AString: string);
var
StrLength: integer;
begin
StrLength := Length(AString);
Fs.Write(StrLength, SizeOf(StrLength));
//if StrLength > 0 then
Fs.Write(AString[1], StrLength);
end;
//------------------------------------------------------------------------------
function FontStringToStyle(AStyle: string): TFontStyles;
begin
Result := [];
if Pos('B', AStyle) <> 0 then Result := Result + [fsBold];
if Pos('I', AStyle) <> 0 then Result := Result + [fsItalic];
if Pos('U', AStyle) <> 0 then Result := Result + [fsUnderline];
if Pos('S', AStyle) <> 0 then Result := Result + [fsStrikeOut];
end;
function FontStyleToString(AStyle: TFontStyles): string;
begin
Result := '';
if (fsBold in AStyle) then Result := Result + 'B';
if (fsItalic in AStyle) then Result := Result + 'I';
if (fsUnderline in AStyle) then Result := Result + 'U';
if (fsStrikeOut in AStyle) then Result := Result + 'S';
end;
//------------------------------------------------------------------------------
{$IFNDEF VER100}
function PolyPointsToString(APoints: PointArray): string;
var
AList: TStringList;
ICount: integer;
begin
AList := TStringList.Create;
try
for ICount := 0 to High(APoints) do
begin
AList.Add(IntToStr(APoints[ICount].x));
AList.Add(IntToStr(APoints[ICount].y));
end;
Result := AList.CommaText;
finally
AList.Free;
end;
end;
procedure PolyPointsFromString(var APoints: PointArray; AString: string);
var
AList: TStringList;
ICount: integer;
begin
AList := TStringList.Create;
try
AList.CommaText := AString;
SetLength(APoints, AList.Count div 2);
ICount := 0;
while ICount <> AList.Count do
begin
APoints[ICount div 2].x := StrToInt(AList[ICount]);
APoints[ICount div 2].y := StrToInt(AList[ICount+1]);
Inc(ICount, 2);
end;
finally
AList.Free;
end;
end;
{$ENDIF}
//------------------------------------------------------------------------------
procedure StringToStream(AString: string; AStream: TStream);
begin
if Assigned(AStream) then
AStream.Write(Pointer(AString)^, Length(AString));
end;
function StreamToString(AStream: TStream): string;
begin
if Assigned(AStream) then
begin
AStream.Seek(soFromBeginning, 0);
SetString(Result, PChar(nil), AStream.Size);
AStream.ReadBuffer(Pointer(Result)^, AStream.Size);
end
else
Result := '';
end;
//------------------------------------------------------------------------------
function BitmapFromString(AString: string): TBitmap;
var
AStream: TMemoryStream;
begin
Result := nil;
if AString <> '' then
begin
AStream := TMemoryStream.Create;
try
StringToStream(AString, AStream);
AStream.Seek(soFromBeginning, 0);
Result := TBitmap.Create;
Result.LoadFromStream(AStream);
finally
AStream.Free;
end;
end;
end;
function BitmapToString(ABitmap: TBitmap): string;
var
AStream: TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
ABitmap.SaveToStream(AStream);
Result := StreamToString(AStream);
finally
AStream.Free;
end;
end;
function MetafileFromString(AString: string): TMetafile;
var
AStream: TMemoryStream;
begin
Result := nil;
if AString <> '' then
begin
AStream := TMemoryStream.Create;
try
StringToStream(AString, AStream);
AStream.Seek(soFromBeginning, 0);
Result := TMetafile.Create;
Result := MetafileFromStream(AStream);
finally
AStream.Free;
end;
end;
end;
function MetafileToString(AMetafile: TMetafile): string;
var
AStream: TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
MetaFileToStream(AStream, AMetafile);
Result := StreamToString(AStream);
finally
AStream.Free;
end;
end;
//------------------------------------------------------------------------------
{function PenToString(APen: TPen): string;
var
AStream: TMemoryStream;
TempInt: integer;
begin
AStream := TMemoryStream.Create;
try
with AStream do
begin
TempInt := APen.Color;
AStream.Write(TempInt, SizeOf(TempInt));
Result := StreamToString(AStream);
end;
finally
AStream.Free;
end;
end;
procedure PenFromString(AString: string; APen: TPen);
begin
end;}
end.